home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-15 | 3.8 KB | 147 lines | [TEXT/CWIE] |
- /*************************************************************************************
- #
- # Color Search Procs.cp
- #
- # This file defines a number of commonly used color search procs. For the encoder,
- # we only use one of the procs, which returns white if the color of a pixel is within
- # a certain delta of a key color, and returns black for all other cases. We can use
- # this to quickly create masks of an image.
- #
- #
- # Author: Timothy Carroll
- # Apple Developer Technical Support
- # timc@apple.com
- #
- # Modification History:
- #
- # 8/15/96 TMC Initial Release
- #
- # Copyright © 1996 Apple Computer, Inc., All Rights Reserved
- #
- #
- # You may incorporate this sample code into your applications without
- # restriction, though the sample code has been provided "AS IS" and the
- # responsibility for its operation is 100% yours. However, what you are
- # not permitted to do is to redistribute the source as "DSC Sample Code"
- # after having made changes. If you're going to re-distribute the source,
- # we require that you make it clear in the source that the code was
- # descended from Apple Sample Code, but that you've made changes.
- #
- *************************************************************************************/
-
-
-
- #include "Color Search Procs.h"
-
- SInt32 gSearchDelta = 0x2000;
- RGBColor gMaskColor = {0,0,0};
-
- // We're going to define a custom color search proc. This will be used by the class routines
- // to create the mask.
-
- static pascal Boolean MaskSearchProc (RGBColor *theColor, long *result);
- static pascal Boolean LightenSearchProc (RGBColor *theColor, long *result);
- static pascal Boolean DarkenSearchProc (RGBColor *theColor, long *result);
-
- // We want to be able to compile for powermacs, so we'll provide UPPs for all
- // of the custom search procs. Note that we don't actually allow passing
- // the search proc's directly, only the UPPs.
- ColorSearchUPP MaskSearchProcUPP = NewColorSearchProc(MaskSearchProc);
- ColorSearchUPP LightenSearchProcUPP = NewColorSearchProc(LightenSearchProc);
- ColorSearchUPP DarkenSearchProcUPP = NewColorSearchProc(DarkenSearchProc);
-
-
- // The Mask search proc needs to be able to pass in a specific color to be used as
- // the mask. We can't change the calling parameters or provide it via a handle
- // (unlike some System 7 routines, this one doesn't pass any "user data".).
- // So any additional parameters, like our key color and the delta, need to be
- // defined and passed in as global variables.
-
-
- pascal Boolean MaskSearchProc (RGBColor *theColor, long *result)
- {
- long temp;
- if (theColor->red > gMaskColor.red)
- {
- temp = theColor->red - gMaskColor.red;
- if (temp > gSearchDelta)
- {
- *theColor = kBlack;
- return false;
- }
- }
- else
- {
- temp = gMaskColor.red - theColor->red;
- if (temp > gSearchDelta)
- {
- *theColor = kBlack;
- return false;
- }
- }
-
- if (theColor->green > gMaskColor.green)
- {
- temp = theColor->green - gMaskColor.green;
- if (temp > gSearchDelta)
- {
- *theColor = kBlack;
- return false;
- }
- }
- else
- {
- temp = gMaskColor.green - theColor->green;
- if (temp > gSearchDelta)
- {
- *theColor = kBlack;
- return false;
- }
- }
-
- if (theColor->blue > gMaskColor.blue)
- {
- temp = theColor->blue - gMaskColor.blue;
- if (temp > gSearchDelta)
- {
- *theColor = kBlack;
- return false;
- }
- }
- else
- {
- temp = gMaskColor.blue - theColor->blue;
- if (temp > gSearchDelta)
- {
- *theColor = kBlack;
- return false;
- }
- }
-
- *theColor = kWhite;
- return false;
-
- #pragma unused (result)
- }
-
-
- pascal Boolean DarkenSearchProc (RGBColor *theColor, long *result)
- {
- (theColor->red) >>= 1;
- (theColor->green) >>= 1;
- (theColor->blue) >>= 1;
-
- return false;
- #pragma unused (result)
- }
-
-
- pascal Boolean LightenSearchProc (RGBColor *theColor, long *result)
- {
- (theColor->red) <<= 1;
- (theColor->green) <<= 1;
- (theColor->blue) <<= 1;
-
- return false;
- #pragma unused (result)
- }